home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 November: Tool Chest / Dev.CD Nov 96 TC / Dev.CD Nov 96 TC.toast / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / vidDrvrS2000.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  15.2 KB  |  548 lines  |  [TEXT/MPS ]

  1. (*
  2.     vidDrvrS2000(cmd,parameters) -- Driver for the Sony 2000 videodisc player. The cmd parameter specifies the
  3.         function to be performed (p1 is the first parameter after cmd; p2 is the second, etc.):
  4.  
  5.                     Command        Function
  6.                     ---------        --------
  7.                     chapter            Return the chapter currently being displayed.
  8.                     control            Execute a series of control functions. Each addition parameter is a keyword to be
  9.                                         executed. If the keyword doesn't make sense here, pass it on to configureSPort.
  10.                                         The following keywords are understood by the video driver:
  11.                                                     Keyword                        Function
  12.                                                     --------                        --------
  13.                                                     init or reset                    Reset the player, configure the serial port (the baud rate is set to
  14.                                                                                         the highest available for the selected player).
  15.                                                     eject or reject                Eject the disc from the player.
  16.                                                     audioOff                        Turn off both audio channels.
  17.                                                     audio1On                        Turn on audio channel 1.
  18.                                                     audio2On                        Turn on audio channel 2.
  19.                                                     stereoOn                        Turn on both audio channels.
  20.                                                     pictureOn/pictureOff    Turn on/off the picture.
  21.                                                     framesOn/framesOff    Turn on/off the display of frame numbers.
  22.                                                     frameMode                    Set player to frame number mode.
  23.                                                     chapterMode                    Set player to chapter number mode.
  24.                                                     timeMode                        Set player to time mode.
  25.                                                     defaultComm                    Set default communications settings for this player.
  26.                     extended        Execute a function specific to the player. This player doesn't have any (yet).
  27.                     fps                Set the frames per second for the next playVideo command to p1, which can be a number or
  28.                                         one of "slowest", "slower", "slow", "normal", "fast", "faster", "fastest".
  29.                     frame            Return the current frame number.
  30.                     name            Return the long name of the player.
  31.                     play                Start a sequence playing, from p1 to p2, which are frame numbers, chapter numbers, or times,
  32.                                         depending upon the mode.
  33.                     scan                Scan forward or backward, depending upong whether p1 is "forward" or "backward".
  34.                     search            Search to frame, chapter, or time p1.
  35.                     sendCmd        Send command p1 to the player and wait for an acknowlege.
  36.                     speeds            Return the frames per second speeds allowed with this player.
  37.                     status            Return the status of the play, which is a comma-separated list containing:
  38.                                                         Keyword                                            Meaning
  39.                                                         --------                                            --------
  40.                                                         doorOpen or park or still or play        State of player.
  41.                                                         CLV or CAV                                        Type of disc.
  42.                                                         disc12inch or disc8inch                        Size of disc being played.
  43.                                                         side1 or side2                                    Side of disc being played.
  44.                     step                Step p1 frames forward (or backward if it's negative), and do it p2 times.
  45.                     time                Return the time of the frame currently being displayed, in 1/60ths of a second since the start
  46.                                         of the disc.
  47.                     version            Return the version of this player driver.
  48.  
  49.     To compile and link this file using Macintosh Programmer's Workshop,
  50.  
  51.         pascal -w vidDrvrS2000.p
  52.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=8033 -sn Main=vidDrvrS2000 ∂
  53.             vidDrvrS2000.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
  54.  
  55.     Copyright © 1988 Apple Computer, Inc.
  56.  
  57.     2/88 - Initial coding by Harry R. Chesley.
  58. *)
  59.  
  60. {$R-}
  61.  
  62. {$S vidDrvrS2000 }     { Segment name must be the same as the command name. }
  63.  
  64. unit DummyUnit;
  65.  
  66. interface
  67.  
  68. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  69.  
  70. procedure EntryPoint(paramPtr: XCmdPtr);
  71.     
  72. implementation
  73.  
  74. type
  75.  
  76. Str31 = String[31];
  77.  
  78. procedure vidDrvrS2000(paramPtr: XCmdPtr); forward;
  79.  
  80. procedure EntryPoint(paramPtr: XCmdPtr);
  81.  
  82.     begin
  83.         vidDrvrS2000(paramPtr);
  84.     end;
  85.  
  86. procedure vidDrvrS2000(paramPtr: XCmdPtr);
  87.  
  88.     var returnValue: str255;
  89.         pCount: integer;
  90.         p1, p2: str255;
  91.         str: str255;
  92.         i: integer;
  93.         inChapterMode: boolean;
  94.  
  95.     {$I XCmdGlue.inc}
  96.  
  97.     procedure Fail(errMsg: Str255); { set theResult and quit }
  98.         begin
  99.             paramPtr^.returnValue := PasToZero(errMsg);
  100.             exit(vidDrvrS2000);
  101.         end;
  102.  
  103.     {$I VideoUtil.inc}
  104.  
  105.     procedure sendCmd(theCommand: str255);
  106.         { Send a command to the player and wait for the ack. }
  107.  
  108.         var i: integer;
  109.  
  110.         begin
  111.             for i := 1 to length(theCommand) do
  112.                 begin
  113.                     SendCardMessage(Concat('sendSPort "',Copy(theCommand,i,1),'"'));
  114.                     EvalAndDispose('RecvUpTo(numToChar(10),600,empty)');
  115.                 end;
  116.         end;
  117.  
  118.     function frame: str255;
  119.         { Return the current frame number. }
  120.  
  121.         var str: str255;
  122.             endTick: longInt;
  123.  
  124.         begin
  125.             { Get the current frame number... }
  126.             SendCardMessage('sendSPort "`"');
  127.             str := '';
  128.             endTick := TickCount+120;
  129.             repeat
  130.                 str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
  131.                 if length(str) = 1 then
  132.                     if str[1] = chr(11) then
  133.                         begin
  134.                             frame := 'noDisc';
  135.                             exit(frame);
  136.                         end;
  137.             until (length(str) >= 5) or (TickCount > endTick);
  138.             if length(str) < 5 then frame := 'noAnswer'
  139.             else frame := str;
  140.         end;
  141.  
  142.     function chapter: str255;
  143.         { Return the current chapter number. }
  144.  
  145.         var str: str255;
  146.             endTick: longInt;
  147.  
  148.         begin
  149.             { Get the current chapter number... }
  150.             SendCardMessage('sendSPort "v"');
  151.             str := '';
  152.             endTick := TickCount+120;
  153.             repeat
  154.                 str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
  155.                 if length(str) = 1 then
  156.                     if str[1] = chr(11) then
  157.                         begin
  158.                             chapter := 'noChapters';
  159.                             exit(chapter);
  160.                         end;
  161.             until (length(str) >= 2) or (TickCount > endTick);
  162.             if length(str) < 2 then chapter := 'noAnswer'
  163.             else chapter := str;
  164.         end;
  165.  
  166.     function time: str255;
  167.         { Return the time of the current frame. }
  168.  
  169.         begin
  170.             time := 'notImplemented';
  171.         end;
  172.  
  173.     procedure search(var toFrame: str255; blankSearch: boolean);
  174.         { Search to the specified frame. (Note: This player can't blank on search.) }
  175.  
  176.         begin
  177.             sendCmd(Concat('C',toFrame,'@'));
  178.             EvalAndDispose('recvUpTo(numToChar(1),600,empty)');
  179.         end;
  180.  
  181.     procedure stop;
  182.         { Stop the player. }
  183.  
  184.         begin
  185.             sendCmd('O');
  186.         end;
  187.  
  188.     procedure control(var keywd: str255);
  189.         { Handle control commands. }
  190.  
  191.         type
  192.             audioModes = (off,oneOn,twoOn,stereo);
  193.  
  194.         var numberOfParms: integer;
  195.             i: integer;
  196.             parm: str255;
  197.  
  198.         procedure ejectPlayer;
  199.             { Eject the disc. }
  200.     
  201.             begin
  202.                 { No eject for this player. }
  203.             end;
  204.     
  205.         procedure audio(onOff: audioModes);
  206.             { Set the audio mode. }
  207.     
  208.             begin
  209.                 { Send the appropriate audio channel command. }
  210.                 case onOff of
  211.                         off:
  212.                             begin
  213.                                 sendCmd('G');
  214.                                 sendCmd('I');
  215.                             end;
  216.                         oneOn:
  217.                             begin
  218.                                 sendCmd('F');
  219.                                 sendCmd('I');
  220.                             end;
  221.                         twoOn:
  222.                             begin
  223.                                 sendCmd('G');
  224.                                 sendCmd('H');
  225.                             end;
  226.                         stereo:
  227.                             begin
  228.                                 sendCmd('F');
  229.                                 sendCmd('H');
  230.                             end;
  231.                         end;
  232.             end;
  233.     
  234.         procedure picture(onOff: boolean);
  235.             { Turn the picture on or off. }
  236.     
  237.             begin
  238.                 { No picture control with this player. }
  239.             end;
  240.     
  241.         procedure frames(onOff: boolean);
  242.             { Turn frame display on or off. }
  243.     
  244.             begin
  245.                 { Send the appropriate frame display command. }
  246.                 if onOff then sendCmd('P')
  247.                 else sendCmd('Q');
  248.             end;
  249.     
  250.         procedure defaultComm;
  251.             { Set the default communication parameters. }
  252.  
  253.             begin
  254.                 { Set the port configuration. }
  255.                 SendCardMessage('configureSPort baud9600,echoOff,editOff,linefeedOff,stripOff');
  256.             end;
  257.  
  258.         procedure setMode(theMode: str255);
  259.             { Set the frame/chapter/time mode. }
  260.     
  261.             begin
  262.                 SetStrGlobal('videoMode',theMode);
  263.                 if StringEqual(theMode,'chapterMode') then sendCmd('Vi')
  264.                 else if StringEqual(theMode,'timeMode') then sendCmd('VU')
  265.                 else sendCmd('VU');
  266.             end;
  267.     
  268.         procedure initPlayer;
  269.             { Initialize the player. }
  270.     
  271.             begin
  272.                 { Empty out the globals. }
  273.                 SetStrGlobal('videoMode','');
  274.                 SetStrGlobal('blankNextVideo','');
  275.                 SetStrGlobal('videoSpeed','');
  276.     
  277.                 { Send the reset command for this player. }
  278.                 sendCmd('V');
  279.  
  280.                 { Force it to stop. }
  281.                 stop;
  282.  
  283.                 { Reset the player to known defaults. }
  284.                 setMode('');
  285.                 audio(stereo);
  286.                 frames(false);
  287.                 picture(true);
  288.             end;
  289.     
  290.         begin
  291.             if StringEqual(keywd,'init') or StringEqual(keywd,'reset') then initPlayer
  292.             else if StringEqual(keywd,'eject') or StringEqual(keywd,'reject') then ejectPlayer
  293.             else if StringEqual(keywd,'audioOff') then audio(off)
  294.             else if StringEqual(keywd,'audio1On') then audio(oneOn)
  295.             else if StringEqual(keywd,'audio2On') then audio(twoOn)
  296.             else if StringEqual(keywd,'stereoOn') then audio(stereo)
  297.             else if StringEqual(keywd,'pictureOn') then picture(true)
  298.             else if StringEqual(keywd,'pictureOff') then picture(false)
  299.             else if StringEqual(keywd,'framesOn') then frames(true)
  300.             else if StringEqual(keywd,'framesOff') then frames(false)
  301.             else if StringEqual(keywd,'defaultComm') then defaultComm
  302.             else if StringEqual(keywd,'frameMode') then setMode('')
  303.             else if StringEqual(keywd,'chapterMode') then setMode('chapterMode')
  304.             else if StringEqual(keywd,'timeMode') then setMode('timeMode')
  305.             else SendCardMessage(Concat('configureSPort ',keywd));
  306.         end;
  307.  
  308.     function extended(var keywd: str255): str255;
  309.         { Execute an extended command or function. }
  310.  
  311.         begin
  312.             { No extended commands for this player. }
  313.         end;
  314.  
  315.     procedure fps(var fpsKeywd: str255);
  316.         { Set the frames per second. }
  317.  
  318.         var speed: str255;
  319.  
  320.         begin
  321.             speed := '';
  322.  
  323.             { Default speed settings are fine, except: }
  324.             if StringEqual(fpsKeywd,'fast') then speed := '90'
  325.             else if StringEqual(fpsKeywd,'fastest') then speed := '90';
  326.  
  327.             { Set it. }
  328.             if speed <> '' then SetStrGlobal('videoSpeed',speed);
  329.         end;
  330.  
  331.     function name: str255;
  332.         { Return the long name of the player. }
  333.  
  334.         begin
  335.             name := 'Sony 2000';
  336.         end;
  337.  
  338.     procedure play(var firstFrame,lastFrame,speed: str255; blankSearch, chapterMode: boolean);
  339.         { Play a segment. }
  340.  
  341.         var lastFrameNum: longInt;
  342.             startHere: boolean;
  343.             playToLast: boolean;
  344.             fpsNum: longInt;
  345.             rev: boolean;
  346.  
  347.         begin
  348.             { Figure out if we're playing to special (non-numeric markers). }
  349.             startHere := StringEqual(firstFrame,'here');
  350.             playToLast := StringEqual(lastFrame,'lastFrame');
  351.             if playToLast then
  352.                 begin
  353.                     if chapterMode then
  354.                         begin
  355.                             lastFrame := '99';
  356.                             lastFrameNum := 99;
  357.                         end
  358.                     else
  359.                         begin
  360.                             lastFrame := '54000';
  361.                             lastFrameNum := 54000;
  362.                         end;
  363.                 end
  364.             else lastFrameNum := StrToLong(lastFrame);
  365.             fpsNum := StrToLong(speed);
  366.  
  367.             { Figure out whether we're playing forward or reverse. }
  368.             rev := (not playToLast) and
  369.                         (((not startHere) and (lastFrameNum < StrToLong(firstFrame))) or (lastFrameNum = 0));
  370.         
  371.             { Go to the first frame. }
  372.             if (not startHere) and ((not chapterMode) or playToLast or (lastFrameNum = 0)) then
  373.                 search(firstFrame,blankSearch);
  374.             { Play it. }
  375.             if playToLast and (fpsNum = 30) then sendCmd(':')
  376.             else if (lastFrameNum = 0) and (fpsNum = 30) then sendCmd('J')
  377.             else
  378.                 begin
  379.                     if (not playToLast) and (lastFrameNum <> 0) and ((fpsNum = 30) or (not chapterMode)) then
  380.                         begin
  381.                             sendCmd('D');
  382.                             if not playToLast then
  383.                                 begin
  384.                                     if chapterMode then sendCmd(Concat(LongToStr(lastFrameNum-1),'@01@'))
  385.                                     else sendCmd(Concat(lastFrame,'@01@'));
  386.                                 end
  387.                             else sendCmd('@01@');
  388.                         end;
  389.                     if fpsNum > 30 then
  390.                         begin
  391.                             if rev then sendCmd('K')
  392.                             else sendCmd(';');
  393.                         end
  394.                     else if fpsNum < 30 then
  395.                         begin
  396.                             if rev then sendCmd('M')
  397.                             else sendCmd('=');
  398.                             if fpsNum = 15 then sendCmd('2@')
  399.                             else if fpsNum = 10 then sendCmd('3@')
  400.                             else if fpsNum = 3 then sendCmd('10@')
  401.                             else sendCmd('30@');
  402.                         end;
  403.                 end;
  404.         end;
  405.  
  406.     function scan(scanForward: boolean): str255;
  407.         { Scan forward (is scanForward is true) or backward. }
  408.  
  409.         begin
  410.             if scanForward then sendCmd('>')
  411.             else sendCmd('N');
  412.             scan := 'only once';
  413.         end;
  414.  
  415.     procedure step(goForward: boolean);
  416.         { Step one frame forward (if goForward is true) or backward. }
  417.  
  418.         begin
  419.             if goForward then SendCmd('=O')
  420.             else SendCmd('MO');
  421.         end;
  422.  
  423.     function speeds: str255;
  424.         { Return the valid speeds. }
  425.  
  426.         begin
  427.             speeds := '1,3,10,15,30,90';
  428.         end;
  429.  
  430.     function status: str255;
  431.         { Return the current status of the player. }
  432.  
  433.         var str3, str5: str255;
  434.             endTick: longInt;
  435.             charCount: integer;
  436.             theResult: str255;
  437.  
  438.         begin
  439.             { Get the current status... }
  440.             SendCardMessage('sendSPort "g"');
  441.             endTick := TickCount+120;
  442.             repeat charCount := StrToLong(Evalstr('charsAvailable()'));
  443.             until (charCount >= 5) or (TickCount > endTick);
  444.             { If we got something... }
  445.             if charCount >= 5 then
  446.                 begin
  447.                     { str3 := character three. }
  448.                     EvalAndDispose('recvChars(2)');
  449.                     str3 := EvalStr('recvChars(1)');
  450.                     if length(str3) = 0 then
  451.                         begin
  452.                             str3[0] := chr(1); str3[1] := chr(0);
  453.                         end;
  454.                     { str5 := character five. }
  455.                     EvalAndDispose('recvChars(1)');
  456.                     str5 := EvalStr('recvChars(1)');
  457.                     if length(str5) = 0 then
  458.                         begin
  459.                             str5[0] := chr(1); str5[1] := chr(0);
  460.                         end;
  461.                     { Figure out the current status. }
  462.                     { Figure out the current status. }
  463.                     if BitAnd(ord(str5[1]),127) = 0 then theResult := 'park,'
  464.                     else if BitAnd(ord(str5[1]),96) <> 0 then theResult := 'still,'
  465.                     else theResult := 'play,';
  466.                     if BitAnd(ord(str3[1]),32) <> 0 then theResult := Concat(theResult,'CLV,')
  467.                     else theResult := Concat(theResult,'CAV,');
  468.                     if BitAnd(ord(str3[1]),16) <> 0 then theResult := Concat(theResult,'disc12inch')
  469.                     else theResult := Concat(theResult,'disc8inch');
  470.                     status := theResult;
  471.                 end
  472.             else status := 'noAnswer';
  473.         end;
  474.  
  475.     function version: str255;
  476.         { Return the version of this player driver. }
  477.  
  478.         begin
  479.             version := 'S2000 1.2';
  480.         end;
  481.  
  482.     begin
  483.         pCount := paramPtr^.paramCount;
  484.  
  485.         if pCount <= 0 then Fail('parameter count is not > 0');
  486.  
  487.         if pCount > 1 then GetStrParm(2,p1)
  488.         else p1 := '';
  489.         if pCount > 2 then GetStrParm(3,p2)
  490.         else p2 := '';
  491.  
  492.         GetStrParm(1,str);
  493.  
  494.         returnValue := '';
  495.  
  496.         if StringEqual(str,'chapter') then returnValue := chapter
  497.         else if StringEqual(str,'control') then
  498.             begin
  499.                 for i := 2 to pCount do
  500.                     begin
  501.                         GetStrParm(i,str);
  502.                         control(str);
  503.                     end;
  504.             end
  505.         else if StringEqual(str,'extended') then returnValue := extended(p1)
  506.         else if StringEqual(str,'fps') then fps(p1)
  507.         else if StringEqual(str,'frame') then returnValue := frame
  508.         else if StringEqual(str,'name') then returnValue := name
  509.         else if StringEqual(str,'play') then
  510.             begin
  511.                 GetStrGlobal('videoMode',str);
  512.                 inChapterMode := StringEqual(str,'chapterMode');
  513.                 GetStrGlobal('blankNextVideo',str);
  514.                 if str = '' then
  515.                     begin
  516.                         GetStrGlobal('videoSpeed',str);
  517.                         play(p1,p2,str,false,inChapterMode);
  518.                     end
  519.                 else
  520.                     begin
  521.                         GetStrGlobal('videoSpeed',str);
  522.                         play(p1,p2,str,true,inChapterMode);
  523.                     end;
  524.             end
  525.         else if StringEqual(str,'scan') then
  526.             begin
  527.                 if length(p1) < 1 then returnValue := scan(true)
  528.                 else returnValue := scan(not ((p1[1] = 'b') or (p1[1] = 'B')));
  529.             end
  530.         else if StringEqual(str,'search') then
  531.             begin
  532.                 GetStrGlobal('blankNextVideo',str);
  533.                 search(p1,str <> '');
  534.             end
  535.         else if StringEqual(str,'sendCmd') then sendCmd(p1)
  536.         else if StringEqual(str,'step') then step(p1 = '1')
  537.         else if StringEqual(str,'speeds') then returnValue := speeds
  538.         else if StringEqual(str,'status') then returnValue := status
  539.         else if StringEqual(str,'stop') then stop
  540.         else if StringEqual(str,'time') then returnValue := time
  541.         else if StringEqual(str,'version') then returnValue := version;
  542.  
  543.         { Return the result (if any). }
  544.         paramPtr^.returnValue := PasToZero(returnValue)
  545.     end;
  546.  
  547. end.
  548.